package com.fcx.workai.jinchang.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hxh.component.basicore.Base.adapter.BaseRecyAdapter;
import com.hxh.component.basicore.Base.onRecyItemClick;

import com.hxh.component.business.ui.bean.UserCompanyListBean;
import com.fcx.workai.jinchang.R;


public class MyChooseCompanyAdapter extends BaseRecyAdapter<UserCompanyListBean.ItemsBean, MyChooseCompanyAdapter.VH> {
    private String mCompany;

    public MyChooseCompanyAdapter(Context context) {
        super(context);
    }

    public MyChooseCompanyAdapter(Context context,String chooseCompany, onRecyItemClick<UserCompanyListBean.ItemsBean,VH> itemClick ) {
        super(context);
        this.mCompany = chooseCompany;
        setmItemClickCallBack(itemClick);
    }

    @Override
    public VH newViewHolder(View view) {
        return new VH(view);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_choose_company_list;
    }

    @Override
    public void onBindViewHolder(final VH holder, final int position) {
        final UserCompanyListBean.ItemsBean item = getmDatas().get(position);

        holder.tv_company_name.setText(item.getName());

        if (mCompany.equals(item.getName())){
            holder.iv_select.setSelected(true);
            holder.rl_company.setBackground(getRES_drawable(R.drawable.shape_white_angle3_blue_stroke_bg));
        }else {
            holder.iv_select.setSelected(false);
            holder.rl_company.setBackground(getRES_drawable(R.drawable.shape_white_angle3_bg));
        }


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCompany = item.getName();
                notifyDataSetChanged();
                getmItemClickCallBack().onClick(position,ITEMMAINVIEW,item,holder);
            }
        });
    }

    public class VH extends RecyclerView.ViewHolder {
        private RelativeLayout rl_company;
        private TextView tv_company_name;
        private ImageView iv_select;
        public VH(View itemView) {
            super(itemView);
            rl_company = (RelativeLayout) itemView.findViewById(R.id.rl_company);
            iv_select = (ImageView) itemView.findViewById(R.id.iv_select);
            tv_company_name = (TextView) itemView.findViewById(R.id.tv_company_name);
        }
    }
}